﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Zero.UControl.Component
{
    /// <summary>
    /// ImageWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ImageWindow : Window
    {
        private double scaleSize = 1.0;
        private double angle = 0;

        public ImageWindow(string imagePath)
        {
            if (imagePath == null)  
                throw new ArgumentException("图片路径不能为空");
            InitializeComponent();
            Part_Img.Source = new BitmapImage(new Uri(imagePath, UriKind.RelativeOrAbsolute));
        }

        private void Root_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            if(e.Delta > 0)
            {
                scaleSize = Math.Min(10, scaleSize + 0.1);
                scaleTrans.ScaleX = scaleSize;
                scaleTrans.ScaleY = scaleSize;
            }
            else
            {
                scaleSize = Math.Max(0.1, scaleSize - 0.1);
                scaleTrans.ScaleX = scaleSize;
                scaleTrans.ScaleY = scaleSize;
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }


        private void Zoom_Btn_Click(object sender, RoutedEventArgs e)
        {
            scaleSize = Math.Max(0.1, scaleSize - 0.1);
            scaleTrans.ScaleX = scaleSize;
            scaleTrans.ScaleY = scaleSize;
        }

        private void Enlarge_Btn_Click(object sender, RoutedEventArgs e)
        {
            scaleSize = Math.Min(10, scaleSize + 0.1);
            scaleTrans.ScaleX = scaleSize;
            scaleTrans.ScaleY = scaleSize;
        }

        private void OriginSize_Btn_Click(object sender, RoutedEventArgs e)
        {
            scaleSize = 1.0;
            scaleTrans.ScaleX = scaleSize;
            scaleTrans.ScaleY = scaleSize;
        }

        private void CounterClockWise_Btn_Click(object sender, RoutedEventArgs e)
        {
            angle -= 90;
            rotateTrans.Angle = angle;
        }

        private void ClockWise_Btn_Click(object sender, RoutedEventArgs e)
        {
            angle += 90;
            rotateTrans.Angle = angle;
        }
    }
}
